package com.xuan.juc.daemonTest;

import java.util.concurrent.TimeUnit;

public class DaemonTest {

    public static void main(String[] args) throws InterruptedException {
        myThread myThread = new myThread();

        Thread thread = new Thread(myThread);
        thread.setDaemon(true);// 设置守护线程让其随着主线程结束而结束
        thread.start();

        for (int i = 0; i < 5; i++) {
            System.out.println("爸爸妈妈叫宣梓睿小朋友关电视！");
            TimeUnit.SECONDS.sleep(1);
        }

    }


    static class myThread implements Runnable {

        @Override
        public void run() {

            while (true) {
                System.out.println("宣梓睿在看电视。。。");
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

}


